//
//  ViewController.m
//  ios_flutter_hybrid
//
//  Created by Charles on 2020/2/14.
//  Copyright © 2020 Charles. All rights reserved.
//

#import "ViewController.h"
#import "AppDelegate.h"
@import Flutter;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self
               action:@selector(showFlutter)
     forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"Flutter IM Page" forState:UIControlStateNormal];
    button.backgroundColor = UIColor.systemPinkColor;
    button.frame = CGRectMake(80.0, 210.0, 200.0, 40.0);
    button.layer.cornerRadius = 20;
    button.clipsToBounds = YES;
    button.center = self.view.center;
    [self.view addSubview:button];
}

- (void)showFlutter {
    FlutterEngine *flutterEngine =
    ((AppDelegate *)UIApplication.sharedApplication.delegate).flutterEngine;
    FlutterViewController *flutterViewController =
    [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil];
    [self presentViewController:flutterViewController animated:YES completion:nil];
}
@end
